//
//  PayOffViewController.m
//  HTP
//
//  Created by 王鑫 on 15/11/2.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "PayOffViewController.h"
#import "PayTableViewCell.h"
#import "OrderInfoViewController.h"

@interface PayOffViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic,retain) UITableView *payTableView;

@property (nonatomic, retain) NSDictionary *order1stDic;

@property (nonatomic, retain) NSDictionary *order2rdDic;

@property (nonatomic, retain) NSMutableArray *orderArray;

@end

@implementation PayOffViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setData];
    [self.view addSubview:self.payTableView];
    // Do any additional setup after loading the view.
}

- (UITableView *)payTableView {
    if (!_payTableView) {
        _payTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 39, ScreenWidth, ScreenHeihgt - 40) style:UITableViewStyleGrouped];
//        _payTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@""]]
        _payTableView.backgroundColor = [UIColor colorWithRed:0.93 green:0.93 blue:0.93 alpha:0.7];
        _payTableView.delegate = self;
        _payTableView.dataSource = self;
        _payTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
    }
    
    return _payTableView;
}

//TODO:样式数据设置
- (void)setData {
    _order1stDic = @{
                     @"pay":@"false",
                     @"icoUrl":@"",
                     @"orderName":@"小学三年级教程",
                     @"name":@"孙庆涛",
                     @"price":@"150/h",
                     @"time":@"每周二",
                     @"orderNum":@"95001",
                     @"money":@"1500.00",
                     };
    
    _order2rdDic = @{
                     @"pay":@"false",
                     @"icoUrl":@"",
                     @"orderName":@"小学三年级教程",
                     @"name":@"王海英",
                     @"price":@"180/h",
                     @"time":@"每周二",
                     @"orderNum":@"95001",
                     @"money":@"1500.00",
                     };
    _orderArray = [[NSMutableArray alloc] initWithObjects:_order1stDic,_order2rdDic,nil];
}

//TODO:UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *Identifier = @"Identifier";
    PayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
    
    if (cell == nil) {
        cell = [[PayTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier];
    }
    
    [cell layoutSubviews:[_orderArray objectAtIndex:indexPath.section][@"pay"]];
    [cell setCellData:[_orderArray objectAtIndex:indexPath.section]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderInfoViewController *orderInfoView = [[OrderInfoViewController alloc] init];
    [orderInfoView addCustomTitleWithTitle:@"订单详情"];
    orderInfoView.flag = @"false";
    [[NSNotificationCenter defaultCenter] postNotificationName:ROOTGOTONEXTCONTROLLER object:orderInfoView];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 180;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
